<?php

namespace app\index\service;

use app\common\model\ToolModel;
use app\common\service\MotanService;
use app\index\model\UserModel;
use think\Cache;
use think\Db;

class SkuAttrService
{
    //保存老品
    static public function manufactureEdit($param)
    {
        $audit = ToolModel::find('manage_edit_audit', ['id' => $param['id']], 'audit_remarks,grade,sku,assign_id,audit_status,manufacture_status');
        $param['sku'] = $audit['sku'];
        if (!in_array($audit['manufacture_status'],[2,4])) {
            return returnArr(2, '该状态不允许修改,只能修改待制作和驳回状态的sku!');
        }
        if (!empty($audit['assign_id'])) {
            $param['new'] = 1;
            //新品
        } else {
            $param['new'] = 0;
            //老品
        }
        return self::skuMultipleAttribute($param);
    }

    //前端资料制作编辑解析插入数据库 标题模板 描述模板 速卖通属性 多属性
    static public function skuMultipleAttribute($param)
    {
        //标题模板
        if (empty($param['template'])) {
            return returnArr(2, '标题不能为空');
        }
        //描述模板
        if (empty($param['desc'])) {
            return returnArr(2, '描述不能为空');
        }
        //速卖通
        if (empty($param['cateId'])) {
            $param['cateId']=[];
            //return returnArr(2, '产品属性不能为空');
        }
        if (empty($param['attr'])) {
            return returnArr(2, '多属性不能为空');
        }
        $title = [];
        $param['template'] = json_decode($param['template'], true);
        $title['name'] = $param['template']['name'];
        unset($param['template']['name']);
        $titleValue = [];
        foreach ($param['template'] as $k1 => $v1) {
            $kT = preg_replace("/\[[0-9]*\]/", "", $k1);
            if (empty($titleValue[$kT])) {
                $titleValue[$kT] = $v1;
            } else {
                $titleValue[$kT] .= "卍" . $v1;
            }
        }
        $title['value'] = $titleValue;
        $titleJson = json_encode($title, JSON_UNESCAPED_UNICODE);//标题
        $descJson = json_encode($param['desc'], JSON_UNESCAPED_UNICODE);//描述

        $smt = [];
        $param['smt'] = json_decode($param['smt'], true);
        $smt['cateId'] = join('卍', $param['cateId']);
        $smtValue = [];
        foreach ($param['smt'] as $k2 => $v2) {
            $kT = preg_replace("/\[[0-9]*\]/", "", $k2);
            if (empty($smtValue[$kT])) {
                $smtValue[$kT] = $v2;
            } else {
                $smtValue[$kT] .= "卍" . $v2;
            }
        }
        $smt['value'] = $smtValue;
        $smt['smtKeyValue'] = $param['smtKeyValue']??[];
        $smt['smtKeyValueEn'] = $param['smtKeyValueEn']??[];
        $smtJson = json_encode($smt, JSON_UNESCAPED_UNICODE);//速卖通产品属性

        if ($param['new'] == 1) {
            //新品
            if ($param['type'] == 2) {
                //批量spu保存
                $skuArr = self::getSKuAllBySku($param['sku']);
                $atditIdArr = ToolModel::select('manage_edit_audit', ['sku' => ['in', $skuArr],'assign_id'=>['>',0], 'manufacture_status' => ['in', [2, 4]]], 'id', '', 'id');
                $where = ['id' => ['in', $atditIdArr]];
            } else {
                $where = ['id' => $param['id']];
            }
            ToolModel::updateData($where,
                [
                    'title_template' => $titleJson,
                    'desc_template' => $descJson,
                    'smt_template' => $smtJson,
                    'finish_time' => date('Y-m-d H:i:s',time()),
                ], 'manage_edit_audit'
            );
        } else {
            //老品
            $attrData = [];
            if ($param['type'] == 2) {
                //批量spu保存
                $skuArr = self::getSKuAllBySku($param['sku']);
                $skuLogWhere=['sku'=> ['in',$skuArr]];
                foreach ($skuArr as $v3) {
                    $attrData[] = ['type' => 2, 'sku' => $v3, 'value_json' => $titleJson, 'operator' => CN_NAME, 'creation_time' => TIME];//标题
                    $attrData[] = ['type' => 1, 'sku' => $v3, 'value_json' => $descJson, 'operator' => CN_NAME, 'creation_time' => TIME];//描述
                    $attrData[] = ['type' => 3, 'sku' => $v3, 'value_json' => $smtJson, 'operator' => CN_NAME, 'creation_time' => TIME];//速卖通
                }

                ToolModel::updateData(['sku' =>  ['in',$skuArr],'manufacture_status'=>2,'assign_id'=>0],
                    [
                        'manufacture_status'=>5,
                        'finish_time' => date('Y-m-d H:i:s',time()),
                    ], 'manage_edit_audit'
                );

            } else {
                $skuLogWhere=['sku'=> $param['sku']];
                //单个保存
                $attrData[] = ['type' => 2, 'sku' => $param['sku'], 'value_json' => $titleJson, 'operator' => CN_NAME, 'creation_time' => TIME];//标题
                $attrData[] = ['type' => 1, 'sku' => $param['sku'], 'value_json' => $descJson, 'operator' => CN_NAME, 'creation_time' => TIME];//描述
                $attrData[] = ['type' => 3, 'sku' => $param['sku'], 'value_json' => $smtJson, 'operator' => CN_NAME, 'creation_time' => TIME];//速卖通
            }
            ToolModel::dbInsertOrUpdate('sku_multiple_attribute', $attrData, ['creation_time']);
            //记录修改时间 人
            ToolModel::updateData($skuLogWhere,['modification_operator' => CN_NAME, 'modification_time' => date('Y-m-d H:i:s')],'skus');
            //老品变为已制作
            ToolModel::updateData(['id' => $param['id']],
                [
                    'manufacture_status'=>5,
                    'finish_time' => date('Y-m-d H:i:s',time()),
                ], 'manage_edit_audit'
            );

            $lwh=explode('*',$param['lwh']);
            $temp=[];
            if(count($lwh)!=3){
                return returnArr(2, '自带包装尺寸必填 格式0*0*0');
            }
            $balelwh=explode('*',$param['balelwh']);
            if(count($balelwh)!=3){
                return returnArr(2, '打包后尺寸必填 格式0*0*0');
            }
            if(empty($param['asweight'])){
                return returnArr(2, '自带包装重量不能为空或0');
            }
            $temp['aslength']=$lwh[0];
            $temp['aswide']=$lwh[1];
            $temp['ashight']=$lwh[2];

            $temp['balelength']=$balelwh[0];
            $temp['balewide']=$balelwh[1];//打包后
            $temp['balehight']=$balelwh[2];

            $temp['asweight']=$param['asweight'];//自带包装重量
            $temp['baleweight']=$param['baleweight'];//打包后重量
            $temp['bulk']=$param['bulk'];
            $temp['bulk_unit']=$param['bulk_unit'];
            $temp['modification_operator']=CN_NAME;
            ToolModel::updateData(['sku' => $param['sku']],$temp, 'sku_attribute');


        }
        foreach ($param['attr'] as $v4) {
            if ($param['new'] == 1) {

                if($param['type'] == 2){//批量
                    //新品
                    ToolModel::updateData(['id' => $v4['id'], 'manufacture_status' => ['in', [2, 4]],'assign_id'=>['>',0]],
                        [
                            'color' => $v4['color']??'',
                            'type' => $v4['type']??'',
                            'shape' => $v4['shape']??'',
                            'size' => $v4['size']??'',
                            'pattern' => $v4['pattern']??'',
                            'audit_status'=>1,
                            'manufacture_status'=>3,
                        ], 'manage_edit_audit'
                    );
                    //交接状态改为已制作
/*                    ToolModel::updateData(['sku' => $v4['sku']],
                        [
                            'status'=>4,
                        ], 'sku_handover'
                    );*/
                }else{//单个

                    //新品
                    ToolModel::updateData(['id' => $v4['id'], 'manufacture_status' => ['in', [2, 4]],'assign_id'=>['>',0]],
                        [
                            'color' => $v4['color'],
                            'type' => $v4['type'],
                            'shape' => $v4['shape'],
                            'size' => $v4['size'],
                            'pattern' => $v4['pattern'],
                        ], 'manage_edit_audit'
                    );

                    if($param['sku']==$v4['sku']){
                        //改编辑状态
                        ToolModel::updateData(['id' => $v4['id'], 'manufacture_status' => ['in', [2, 4]],'assign_id'=>['>',0]],
                            [
                                'audit_status'=>1,
                                'manufacture_status'=>3,
                            ], 'manage_edit_audit'
                        );
                        //交接状态改为已制作
/*                        ToolModel::updateData(['sku' => $v4['sku']],
                            [
                                'status'=>4,
                            ], 'sku_handover'
                        );*/
                    }

                }

            } else {
                //老品
                ToolModel::updateData(['sku' => $v4['sku']],
                    [
                        'color' => $v4['color'],
                        'type' => $v4['type'],
                        'shape' => $v4['shape'],
                        'size' => $v4['size'],
                        'pattern' => $v4['pattern'],
                        'modification_operator' => CN_NAME
                    ], 'sku_attribute'
                );
                ToolModel::updateData(['sku' => $v4['sku']],['modification_operator' => CN_NAME, 'modification_time' => date('Y-m-d H:i:s')],'skus');
            }
        }
        return returnArr(1,'成功',['url'=>'/#/Datamanufacture/manufacture']);
    }

    static public function getSKuAllBySku($sku, $field = 'sku')
    {
        $spu = ToolModel::getValue('skus', ['sku' => $sku], 'spu');
        return ToolModel::select('skus', ['spu' => $spu], $field, '', 'sku');
    }

    //获取sku对应的spu 多属性
    static public function getSpuAttrBySku($param)
    {
        $audit = ToolModel::find('manage_edit_audit', ['id' => $param['id']], 'audit_remarks,grade,sku,assign_id');
        $skuArr = self::getSKuAllBySku($audit['sku'], 'name');
        $sku = array_keys($skuArr);
        if ($audit['assign_id']) {
            //新品
            $attr = ToolModel::select('manage_edit_audit', ['sku' => ['in', $sku], 'manufacture_status' => ['in', [2, 4]],'assign_id'=>['>',0]], 'id,sku,color,type,shape,size,pattern');
        } else {
            //老品
            $attr = ToolModel::select('sku_attribute', ['sku' => ['in', $sku]], 'sku,color,type,shape,size,pattern');
        }
        foreach ($attr as &$v) {
            $v['name'] = $skuArr[$v['sku']];
        }
        return returnArr(1, '', $attr);
    }

    //获取标题模板,描述模板
    static public function getTemplate($param)
    {
        //描述模板
        $desc = ToolModel::select('setting_template', ['type' => 1, 'status' => 1], '', 'sort asc ,id asc');
        //标题模板
        $title = ToolModel::select('setting_template', ['type' => 2, 'status' => 1], '', 'sort asc ,id asc');
        $list1 = [];
        foreach ($title as $v1) {
            $list1[$v1['name']][] = $v1;
        }
        $audit = ToolModel::find('manage_edit_audit', ['id' => $param['id']], 'audit_remarks,grade,sku,assign_id,desc_template,title_template,smt_template,manufacture_status');
        if (!in_array($audit['manufacture_status'],[2,4])) {
            return returnArr(2, '该状态不允许修改,只能修改待制作和驳回状态的sku!');
        }
        if (empty($audit['assign_id'])) {
            //老品
            $attr = ToolModel::select('sku_multiple_attribute', ['sku' => $audit['sku']]);
            foreach ($attr as $v2) {
                if ($v2['type'] == 1) {
                    $audit['desc_template'] = json_decode($v2['value_json'], true);
                }
                if ($v2['type'] == 2) {
                    $audit['title_template'] = json_decode($v2['value_json'], true);
                }
                if ($v2['type'] == 3) {
                    $audit['smt_template'] = json_decode($v2['value_json'], true);
                }

            }
            $sku = ToolModel::find('sku_attribute', ['sku' => $audit['sku']], '*');
            $sku['bulk_unit']=strtoupper($sku['bulk_unit']);
            $sku['new']=0;
        } else {
            $sku = ToolModel::find('sku_handover', ['sku' => $audit['sku']], '*');
            $sku['bulk_unit']=strtoupper($sku['bulk_unit']);
            $skuOld = ToolModel::find('sku_attribute', ['sku' => $audit['sku']], '*');
            $sku['develop_link'] =$skuOld['develop_link'];
            $sku['asweight'] =$skuOld['asweight'];
            $sku['baleweight'] =$skuOld['baleweight'];
            $sku['new']=1;
            !empty($audit['desc_template']) && $audit['desc_template'] = json_decode($audit['desc_template'], true);
            !empty($audit['title_template']) && $audit['title_template'] = json_decode($audit['title_template'], true);
            !empty($audit['smt_template']) && $audit['smt_template'] = json_decode($audit['smt_template'], true);
        }
        empty($audit['desc_template']) && $audit['desc_template'] = [];
        empty($audit['title_template']) && $audit['title_template'] = [];
        empty($audit['smt_template']) && $audit['smt_template'] = [];

        if(empty($audit['desc_template']['Features'])){
            $audit['desc_template']['Features']="Features:";
        }
        if(empty($audit['desc_template']['Description'])){
            $audit['desc_template']['Description']="Description:";
        }
        if(empty($audit['desc_template']['Specifications'])){
            $audit['desc_template']['Specifications']="Specifications:";
        }
        if(empty($audit['desc_template']['Package Included'])){
            $audit['desc_template']['Package Included']="Package Included:";
        }
        if(empty($audit['desc_template']['Notes'])){
            $audit['desc_template']['Notes']="Notes:<br>1. Due to the difference between different monitors, the picture may not reflect the actual color of the item. We guarantee the style is the same as shown in the pictures.<br>2. Please allow slight dimension difference due to different manual measurement.";
        }
        $developer = UserModel::getUserById($sku['developer']);
        $sku['developer'] = $developer[$sku['developer']] ?? '';
        $skuMain=ToolModel::find('skus', ['sku' => $audit['sku']], 'name,category_id');
        $sku['name'] =$skuMain['name'];
        $sku['grade'] = $audit['grade'];
        $sku['audit_remarks'] = $audit['audit_remarks'];

        $sku['smt_cid']=Db::table('smt_cate')->alias('a')
            ->join('smt_match_category b','a.cate_id=b.smt_cid')
            ->where('b.cid',$skuMain['category_id'])
            ->value('a.path');
        return returnArr(1, '', ['title' => $list1, 'desc' => $desc, 'skuInfo' => $sku, 'attr' => $audit]);
    }

    //获取速卖通分类属性
    static public function getSmtCateAttributeByCateId($param)
    {
        if (config('app_status') == 'dev') {
            $res = curl('http://test.skumanage.kokoerp.com/index/Datamanufacture/getSmtCateAttributeByCateId', $param);
            return json_decode($res, true);
        }
        $url = config('motanSmtCateAttr');
        $data = [];
        $data['cateId'] = $param['cateId'];
        $par = ['data' => $data];
        $cache=Cache::get('getSmtCateAttributeByCateId'.$param['cateId']);
        if ($cache) {
            return returnArr(1, '', $cache);
        }
        $data = MotanService::execute($url, $par, 'getProductPropertyBycategoryId');
        if (is_array($data) && $data['state'] == '000001') {
            Cache::set('getSmtCateAttributeByCateId'.$param['cateId'],$data['data'],432000);//缓存5天
            return returnArr(1, '', $data['data']);
        }
        return returnArr(-1, '系统繁忙');
    }

    //获取速卖通分类
    static public function getSmtCate()
    {
        if (config('app_status') == 'dev') {
            $res = curl('http://test.skumanage.kokoerp.com/index/Datamanufacture/getSmtCate', []);
            return json_decode($res, true);
        }
        $cache = Cache::get('getAliexpressCateList');
        if ($cache) {
            return returnArr(1, '', $cache);
        }
        $url = config('motanSmtCate');
        $par = ['cate_id' => 0];
        $data = MotanService::execute($url, $par, 'getAliexpressCateList');
        if (is_array($data) && $data['state'] == '000001') {
            $temp=[];
            foreach ($data['data'] as $v){
                $temp[]=['cate_id'=>$v['cate_id'],
                    'name_en'=>$v['cate_name']??'',
                    'path'=>$v['path']];
            }
            ToolModel::dbInsertOrUpdate('smt_cate',$temp);
            $cate = self::toTree($data['data']);
            //缓存两周
            Cache::set('getAliexpressCateList', $cate, 2592000);
            return returnArr(1, '', $cate);
        }
        return returnArr(-1, '系统繁忙');
    }

    public static function toTree($data = [], $pid = 0, $limitLevel = 0, $currentLevel = 0)
    {
        $config = [
            'id' => 'cate_id',        // id名称
            'pid' => 'pid',       // pid名称
            'child' => 'children',    // 子元素键名
        ];
        $trees = [];
        foreach ($data as $k => $v) {
            if ($v[$config['pid']] == $pid) {
                if ($limitLevel > 0 && $limitLevel == $currentLevel) {
                    return $trees;
                }
                unset($data[$k]);
                $childs = self::toTree($data, $v[$config['id']], $limitLevel, ($currentLevel + 1));
                $temp = [
                    'cate_id' => $v['cate_id'],
                    'cate_name_cn' => $v['cate_name_cn'] ?? $v['cate_name']
                ];
                if (!empty($childs)) {
                    $temp[$config['child']] = $childs;
                }
                $trees[] = $temp;
            }
        }
        return $trees;
    }

    //编辑制作-批量编辑
    static public function uploadManufactureEdit($data,$param){
        $error = [];
        $skuArr=array_column($data, '0');
        $edit=ToolModel::select('manage_edit_audit',['cancel'=>0,'sku'=>['in',$skuArr],'manufacture_status'=>['in',[2,4]]],'*');
        $skuInfoNew=[];
        $editSkuId=[];
        $skuOld=[];
        $skuOldInfo=[];
        $newOld=[];
        foreach ($edit as $v1) {
            if($v1['assign_id']>0){
                $skuInfoNew[$v1['sku']]=$v1['desc_template'];
            }else{
                $skuOld[]=$v1['sku'];
                $skuOldInfo[$v1['sku']]=$v1['sku'];
            }
            $newOld[$v1['sku']]=$v1['assign_id'];
            $editSkuId[$v1['sku']]=$v1['id'];
        }
        $intersect=array_intersect(array_keys($skuInfoNew),$skuOld);
        if(!empty($intersect)){
            $error[] = "sku:".join(',',$intersect)." 存在新品和老品,只允许一种存在,不允许上传!  ";
        }
        foreach ($data as $v2) {
            $sku=$v2[0];
            if(empty($editSkuId[$sku])){
                //continue;
                $error[] = "sku: {$sku} 未分派任务!  ";
            }
            !empty($v2[13])&&$zdWLH=$v2[13];
            !empty($v2[14])&&$dbWLH=$v2[14];
            if(!empty($zdWLH)){
                if(count(explode('*',$zdWLH))!=3){
                    $error[] = "sku: {$sku} 自带长宽高格式应为 1*1*1   ";
                }
            }
            if(!empty($dbWLH)){
                if(count(explode('*',$dbWLH))!=3){
                    $error[] = "sku: {$sku} 打包后长宽高格式应为 1*1*1   ";
                }
            }
        }
        //错误信息输出
        if (!empty($error)) {
            return returnArr(2, '',$error);
        }
        $skuInfoOld=ToolModel::select('sku_multiple_attribute',['sku'=>['in',$skuOld],'type'=>1],'value_json','','sku');
        $dbOldDesc=[];
        foreach ($data as $v) {
            $sku=$v[0];
            $temp=[];
            $temp['sku']=$sku;
            !empty($v[1])&&$temp['Features']=$v[1];
            !empty($v[2])&&$temp['Description']=$v[2];
            !empty($v[3])&&$temp['Specifications']=$v[3];
            !empty($v[4])&&$temp['Package Included']=$v[4];
            !empty($v[5])&&$temp['Notes']=$v[5];
            !empty($v[6])&&$temp['color']=$v[6];
            !empty($v[7])&&$temp['type']=$v[7];
            !empty($v[8])&&$temp['shape']=$v[8];
            !empty($v[9])&&$temp['size']=$v[9];
            !empty($v[10])&&$temp['pattern']=$v[10];
            !empty($v[11])&&$temp['asweight']=$v[11];
            !empty($v[12])&&$temp['baleweight']=$v[12];
            !empty($v[13])&&$zdWLH=$v[13];
            !empty($v[14])&&$dbWLH=$v[14];

            if(!empty($zdWLH)){
                $lwh=explode('*',$zdWLH);
                $temp['aslength']=$lwh[0];
                $temp['aswide']=$lwh[1];
                $temp['ashight']=$lwh[2];
            }
            if(!empty($dbWLH)){
                $lwh=explode('*',$dbWLH);
                $temp['balelength']=$lwh[0];
                $temp['balewide']=$lwh[1];
                $temp['balehight']=$lwh[2];
            }
            if(!empty($newOld[$sku])&&$newOld[$sku]>0){
                //新品
                $temp1=[];
                !empty($temp['color'])&&$temp1['color']=$temp['color'];
                !empty($temp['type'])&&$temp1['type']=$temp['type'];
                !empty($temp['shape'])&&$temp1['shape']=$temp['shape'];
                !empty($temp['size'])&&$temp1['size']=$temp['size'];
                !empty($temp['pattern'])&&$temp1['pattern']=$temp['pattern'];
                if(empty($skuInfoNew[$sku])){
                    $desc_template=[];
                }else{
                    $desc_template=json_decode($skuInfoNew[$sku],true);
                }
                if(!empty($temp['Features'])){
                    $desc_template['Features']=$temp['Features'];
                }
                if(!empty($temp['Description'])){
                    $desc_template['Description']=$temp['Description'];
                }
                if(!empty($temp['Specifications'])){
                    $desc_template['Specifications']=$temp['Specifications'];
                }
                if(!empty($temp['Package Included'])){
                    $desc_template['Package Included']=$temp['Package Included'];
                }
                if(!empty($temp['Notes'])){
                    $desc_template['Notes']=$temp['Notes'];
                }
                $temp1['desc_template']=json_encode($desc_template,JSON_UNESCAPED_UNICODE);
                //改编辑状态
                ToolModel::updateData(['id' => $editSkuId[$sku], 'manufacture_status' => ['in', [2, 4]]],
                    [
                        'audit_status'=>1,
                        'manufacture_status'=>3,
                    ], 'manage_edit_audit'
                );

                ToolModel::updateData(['sku'=>$sku],$temp1,'manage_edit_audit');

            }elseif(!empty($skuOldInfo)&&!empty($skuOldInfo[$sku])){
                //老品
                $temp1=[];
                !empty($temp['color'])&&$temp1['color']=$temp['color'];
                !empty($temp['type'])&&$temp1['type']=$temp['type'];
                !empty($temp['shape'])&&$temp1['shape']=$temp['shape'];
                !empty($temp['size'])&&$temp1['size']=$temp['size'];
                !empty($temp['pattern'])&&$temp1['pattern']=$temp['pattern'];

                !empty($temp['aslength'])&&$temp1['aslength']=$temp['aslength'];
                !empty($temp['aswide'])&&$temp1['aswide']=$temp['aswide'];
                !empty($temp['ashight'])&&$temp1['ashight']=$temp['ashight'];
                !empty($temp['balelength'])&&$temp1['balelength']=$temp['balelength'];
                !empty($temp['balewide'])&&$temp1['balewide']=$temp['balewide'];
                !empty($temp['balehight'])&&$temp1['balehight']=$temp['balehight'];

                !empty($temp['asweight'])&&$temp1['asweight']=$temp['asweight'];
                !empty($temp['baleweight'])&&$temp1['baleweight']=$temp['baleweight'];

                !empty($temp1)&&$temp1['modification_operator']=$param['cn_name'];
                !empty($temp1)&&ToolModel::updateData(['sku'=>$sku],$temp1,'sku_attribute');

                if(empty($skuInfoOld[$sku])){
                    $desc_template=[];
                }else{
                    $desc_template=json_decode($skuInfoOld[$sku],true);
                }
                if(!empty($temp['Features'])){
                    $desc_template['Features']=$temp['Features'];
                }
                if(!empty($temp['Description'])){
                    $desc_template['Description']=$temp['Description'];
                }
                if(!empty($temp['Specifications'])){
                    $desc_template['Specifications']=$temp['Specifications'];
                }
                if(!empty($temp['Package Included'])){
                    $desc_template['Package Included']=$temp['Package Included'];
                }
                if(!empty($temp['Notes'])){
                    $desc_template['Notes']=$temp['Notes'];
                }
                $value_json=json_encode($desc_template,JSON_UNESCAPED_UNICODE);
                $dbOldDesc[]=[
                    'sku'=>$sku,
                    'type'=>1,
                    'value_json'=>$value_json,
                    'operator'=>$param['cn_name'],
                    'modification_time'=>TIME,
                    'creation_time'=>TIME,
                ];
                //老品变为已制作
                ToolModel::updateData(['id' =>  $editSkuId[$sku]],
                    [
                        'manufacture_status'=>5,
                        'finish_time' => date('Y-m-d H:i:s',time()),
                    ], 'manage_edit_audit'
                );
                ToolModel::dbInsertOrUpdate('sku_multiple_attribute',$dbOldDesc,['creation_time']);
                ToolModel::updateData(['sku'=>$sku],['modification_operator' => $param['cn_name'], 'modification_time' => date('Y-m-d H:i:s')],'skus');
            }
        }
        unset($data,$skuInfoOld,$skuInfoNew,$edit);
        return returnArr();

    }

}